package com.woniuxy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.entity.DrugMoney;

import com.woniuxy.mapper.DrugMoneyMapper;
import com.woniuxy.service.DrugMoneyService;
import com.woniuxy.service.SaasService;
import com.woniuxy.util.PageParam;
import com.woniuxy.util.ResponseData;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;
@Service
public class DrugMoneyServiceImpl implements DrugMoneyService , SaasService {
@Autowired
private DrugMoneyMapper drugMoneyMapper;
    @Override
    public ResponseData<?> queryAll(PageParam<DrugMoney> pageParam) {
        PageHelper.startPage(pageParam.getPageNum(),pageParam.getPageSize());

        List<DrugMoney> drugMoneyList=drugMoneyMapper.queryAll(pageParam.getParam());
        System.out.println(drugMoneyList);
        for (DrugMoney item : drugMoneyList) {
            if(item.getPpNo()!=null) {
                BigDecimal totalPrice = item.getPrice().multiply(BigDecimal.valueOf(item.getBuyCount()));
                item.setTotalPrice(totalPrice); // 设置总价
            }
        }
//        drugMoneyList.forEach(item -> {
//            BigDecimal totalPrice = item.getPrice().multiply(BigDecimal.valueOf(item.getBuyCount()));
//            item.setTotalPrice(totalPrice);
//        });
        System.out.println(drugMoneyList);


        PageInfo pageInfo =new PageInfo(drugMoneyList);

        return new ResponseData<>().ok(pageInfo);
    }
}
